<?php
	require 'global.php';
	$name = $_GET['name'];
	$name = trim($name);
	$dir = ROOT.'external/widgets/'.$name;
	$fc = file_get_contents($dir.'/widget.info.php');
	$fc = str_replace(array('<?php','?>'), array('',''), $fc);
	$widget = eval($fc);
	
	//获取目录下的.html
	$handle = opendir($dir);
	$widget['html'] = array();
	while (false !== ($file = readdir($handle))) {
		$cur_path = $dir .'/'. $file;
		if(is_file($cur_path) && preg_match('/^[^.]*widget\.html$/', $file)) {
			$content = file_get_contents($cur_path);
			$content = str_replace("<", "&lt;", $content);
			$content = preg_replace('/^\t/', '', $content);
			$id = str_replace("widget.html", "", $file);
			if(empty($id))
				$id = '默认';
			$widget['html'][] = array(
				'name'=>$file,
				'id'=> $id,
				'content'=>$content
			);
		}
	}
?>
	<div class="tabs">
		<ul>
			<li><a href="#base">挂件信息</a></li>
			<?php foreach ($widget['html'] as $html){?>
			<li><a href="#<?php echo $html['id']?>"><?php echo $html['id']?></a></li>
			<?php }?>
			<li><a href="#add">添加模板</a></li>
		</ul>
		<div id="base">
			<label class="widget_name">挂件ID：</label><?php echo $widget['name']?><br/>
			<label class="widget_name">挂件名称：</label><?php echo $widget['display_name']?><br/>
			<label class="widget_name">作者：</label><?php echo $widget['author']?><br/>
			<label class="widget_name">官方地址：</label><?php echo $widget['website']?><br/>
			<label class="widget_name">版本：</label><?php echo $widget['version']?><br/>
			<label class="widget_name">描述：</label><?php echo $widget['desc']?><br/>
		</div>
		<?php foreach ($widget['html'] as $html){?>
		<div class="tabs_content" id="<?php echo $html['id']?>">
			引用：<span style="color:red">&lt;!--{web_cate_widgets htmltype="<?php echo $html['id']=='默认'?'':$html['id']?>" widget_name="<?php echo $name?>" limit_num="3"  nav_id="2122"}--></span><br/>
			<pre><?php echo $html['content']?></pre>
		</div>
		<?php }?>
		<div id="add">
			<form action="/tool/creator/widget/template_add.php" method="post">
				<label class="widget_name">挂件ID：</label>
				<input type="hidden" name="id" value="<?php echo $widget['name']?>">
				<?php echo $widget['name']?><br/>
				<label class="widget_name">模板名称：</label>
					<input style="width:200px" type="text" name="name" />
					（请使用英文、数字或下划线作为模板名称）<br/>
				<label class="widget_name">模板内容：</label>
				<textarea rows="15" style="width:500px;vertical-align: top" name="body">&lt;!-- 模板可以留空，默认数据变量：{$widget_data} --></textarea>
				<div style="text-align: center;">
					<input type="submit" value="创建">
				</div>
			</form>
		</div>
	</div>